package com.ylkj.wx.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ylkj.wx.dao.QuestionInfoTableDAO;
import com.ylkj.wx.dto.QuestionListDTO;
import com.ylkj.wx.service.QuestionInfoTableService;

@Service
public class QuestionInfoTableServiceImpl implements QuestionInfoTableService {
	@Autowired
	private QuestionInfoTableDAO questionInfoTableDAO;
	
	@Override
	public List<QuestionListDTO> findQuestionInfoTable(int pageNum, int pageSize) {
		List<QuestionListDTO> questionsList = questionInfoTableDAO.findQuestionInfoTable(pageNum, pageSize);
		List<Integer> queIdList = new ArrayList<Integer>();
		for (QuestionListDTO questionListDTO : questionsList) {
			queIdList.add(questionListDTO.getQuestionId());
		}
		List<QuestionListDTO> answerList= questionInfoTableDAO.findAnswerInfo(queIdList);
		for (QuestionListDTO questionListDTO : questionsList) {
			for (QuestionListDTO answer : answerList) {
				if (questionListDTO.getQuestionId().equals(answer.getQuestionId())) {
					questionListDTO.setAnwserContent(answer.getAnwserContent());
					questionListDTO.setProvince(answer.getProvince());
					questionListDTO.setPhotoUrl(answer.getPhotoUrl());
					questionListDTO.setLawyerName(answer.getLawyerName());
					questionListDTO.setLawfirmName(answer.getLawfirmName());
					questionListDTO.setCity(answer.getCity());
					questionListDTO.setAreaAddr(answer.getAreaAddr());
					break;
				}
			}
		}
		return questionsList;
	}

	@Override
	public List<QuestionListDTO> findQuestionInfoByQueId(Integer queId) {
		List<Integer> queIdList = new ArrayList<Integer>(); 
		queIdList.add(queId);
		return questionInfoTableDAO.findAnswerInfo(queIdList);
	}

	@Override
	public List<QuestionListDTO> findAnswerInfoByQueId(Integer queId) {
		return questionInfoTableDAO.findAnswerInfoById(queId);
	}
}
